using System;
using System.Threading.Tasks;

namespace CoreManager.Core.Caching
{
    /// <summary>
    /// 缓存服务接口
    /// </summary>
    public interface ICacheService
    {
        /// <summary>
        /// 获取缓存项
        /// </summary>
        /// <typeparam name="T">缓存项类型</typeparam>
        /// <param name="key">缓存键</param>
        /// <returns>缓存项，如果不存在则返回默认值</returns>
        T Get<T>(string key);

        /// <summary>
        /// 异步获取缓存项
        /// </summary>
        /// <typeparam name="T">缓存项类型</typeparam>
        /// <param name="key">缓存键</param>
        /// <returns>缓存项，如果不存在则返回默认值</returns>
        Task<T> GetAsync<T>(string key);

        /// <summary>
        /// 设置缓存项
        /// </summary>
        /// <typeparam name="T">缓存项类型</typeparam>
        /// <param name="key">缓存键</param>
        /// <param name="value">缓存值</param>
        /// <param name="expiration">过期时间（可选）</param>
        void Set<T>(string key, T value, TimeSpan? expiration = null);

        /// <summary>
        /// 异步设置缓存项
        /// </summary>
        /// <typeparam name="T">缓存项类型</typeparam>
        /// <param name="key">缓存键</param>
        /// <param name="value">缓存值</param>
        /// <param name="expiration">过期时间（可选）</param>
        Task SetAsync<T>(string key, T value, TimeSpan? expiration = null);

        /// <summary>
        /// 移除缓存项
        /// </summary>
        /// <param name="key">缓存键</param>
        /// <returns>如果成功移除则返回true，否则返回false</returns>
        bool Remove(string key);

        /// <summary>
        /// 异步移除缓存项
        /// </summary>
        /// <param name="key">缓存键</param>
        /// <returns>如果成功移除则返回true，否则返回false</returns>
        Task<bool> RemoveAsync(string key);

        /// <summary>
        /// 检查缓存项是否存在
        /// </summary>
        /// <param name="key">缓存键</param>
        /// <returns>如果存在则返回true，否则返回false</returns>
        bool Exists(string key);

        /// <summary>
        /// 异步检查缓存项是否存在
        /// </summary>
        /// <param name="key">缓存键</param>
        /// <returns>如果存在则返回true，否则返回false</returns>
        Task<bool> ExistsAsync(string key);

        /// <summary>
        /// 刷新缓存项过期时间
        /// </summary>
        /// <param name="key">缓存键</param>
        /// <param name="expiration">新的过期时间</param>
        /// <returns>如果成功刷新则返回true，否则返回false</returns>
        bool Refresh(string key, TimeSpan expiration);

        /// <summary>
        /// 异步刷新缓存项过期时间
        /// </summary>
        /// <param name="key">缓存键</param>
        /// <param name="expiration">新的过期时间</param>
        /// <returns>如果成功刷新则返回true，否则返回false</returns>
        Task<bool> RefreshAsync(string key, TimeSpan expiration);

        /// <summary>
        /// 清空所有缓存
        /// </summary>
        void Clear();

        /// <summary>
        /// 异步清空所有缓存
        /// </summary>
        Task ClearAsync();
    }
}